package org.example.versi.server;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author mojito
 * @Classname RpcServer
 * @Description TODO
 * @Date 2020/7/20 下午9:07
 **/
@Slf4j
public class RpcServer implements IServer {
    private Map<String, Object> serviceMap = new ConcurrentHashMap<>(8);

    @Override
    public IServer registry(Class<?> face, Object service) {
        if (face.isInstance(service)) {
            serviceMap.put(face.getName(), service);
        }
        return this;
    }

    @Override
    public void publish(int port) {
        //启动服务
        try {
            log.info("service publishing");
            new BootServer(port).serve(serviceMap);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
